import XTree from '@/components/common/XTree.vue'
import PlansService from '@/services/PlansService'
import * as scheduleTaskService from '@/services/ScheduleTaskService'
import * as organizationService from '@/services/OrganizationService'
import msgGroupsService from '@/services/MsgGroupsService'
import * as sysUserService from '@/services/SysUserService'
import moment from 'moment'
import config from '@/config'

const now = new Date()
const DAY_OPTIONS = [
  {text: '今天', date: new Date()},
  {text: '昨天', date: new Date(now.getTime() - 3600 * 1000 * 24)},
  {text: '一周前', date: new Date(now.getTime() - 3600 * 1000 * 24 * 7)}
]

const MONTH_OPTIONS = [
  {text: '最近一周', begin: now, end: new Date(now.getTime() + 3600 * 1000 * 24 * 7)},
  {text: '最近一个月', begin: now, end: new Date(now.getTime() + 3600 * 1000 * 24 * 30)},
  {text: '最近三个月', begin: now, end: new Date(now.getTime() + 3600 * 1000 * 24 * 90)}
]

export default {
  components: {
    'x-tree': XTree
  },
  props: ['sysUser', 'taskType'],
  data: function () {
    return {
      Zero: [],
      One: [],
      Two: [],
      Three: [],
      Four: [],
      Five: [],
      Seven: [],
      Custom: [],
      copyArr: {
        zeroTree: [],
        oneTree: [],
        twoTree: [],
        threeTree: [],
        // fourTree: [],
        // fiveTree: [],
        // sevenTree: [],
        customTree: []
      },
      zeroList: [],
      checkZero: false,
      checkOne: false,
      checkTwo: false,
      checkThree: false,
      checkFour: false,
      checkFive: false,
      checkSeven: false,
      checkCustom: false,
      pickerOptionstime: MONTH_OPTIONS,
      // taskType: [],
      uploadUrl: config.FILE_UPLOAD_URL,
      id: '',
      type: 'add',
      formDisabled: false,
      title: '新建计划任务',
      taskType2: [],
      taskType3: [],
      form: {
        code: '',
        name: '',
        datetype: 0,
        special: '',
        userName: this.$profile.fullname,
        tplansel: 'month',
        starttime: '',
        endtime: '',
        type1: '',
        type2: '',
        type3: '',
        typeZ: '',
        typeradio: false,
        tpbnumber: '0',
        number: '',
        periodEnd: '',
        tpnumipt: '',
        range: '',
        definitiontime: '',
        url: [],
        filterContent: {}, //清空数据
      },
      fileImg: '',
      // fileList: [],
      orglist: [],
      numType: [{
        value: '0',
        label: '数量'
      }
      ],
      taskType1Option: [],
      taskType2Option: [],
      taskType1Often: [],
      taskType2Often: [],
      unit: [],
      typex: '',
      copylist: [],
      // copylistP: [],

      dows: [],
      laws: [],
      egs: [],
      dutys: [],

      copylista: [],
      leaderlist: [],
      checkLeader: false,
      checkedLeader: [],
      checkBroat: false,
      checkedBroat: [],
      checkDuty: false,
      checkedDuty: [],
      checkEg: false,
      checkedEg: [],
      checkLaw: false,
      checkedLaw: [],
      checkDow: false,
      checkedDow: [],

      customize: [],
      checkCustomize: false,
      checkedCustomize: [],
      customizelength: '',
      dialogVisible: false,

      groupData: [],
      ruleForm: {
        name: '',

      },
      dialogVisible1: false,
      rule: {
        name: '',

      },
      ruleGroup: [],
      aa: [],
      cusChil: [],
      checkAll: false,

      fileList: [],
      headers: {
        Authorization: 'Bearer ' + localStorage.getItem('token')
      },
      editcopy: [],
      egslist: [],
      uploadobj: {
        filename: '',
        mimeType: 'txt/doc',
        bus: 'plans'
      },
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      leaderlength: '',
      dowslength: '',
      lawslength: '',
      egslenght: '',
      dutyslength: '',
      taskPid: [],
      treeList2: [],
      filterText: '',
      pickerOptions1: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
            picker.$emit('pick', [start, end])
          }
        }]
        // shortcuts: DAY_OPTIONS.map(opt => {
        //   return {
        //     text: opt.text,
        //     onClick: picker => picker.$emit('pick', opt.date)
        //   }
        // })
      },
      pickerOptions: {
        shortcuts: MONTH_OPTIONS.map(opt => {
          return {
            text: opt.text,
            onClick: picker => picker.$emit('pick', [opt.start, opt.end])
          }
        })
      },
      detailId: '',
      createTime: '',
      organization: [],
      organizaAll: []
    }
  },
  async mounted() {
    this.unit = this.$route.params.searchOrgs.map(item => {
      return {choose: false, name: item.name, num: '', orgId: item.id}
    })
    await this.selectAll();
    await this.getSendList()
    await this.getSendTree()
    await this.getCustom();
    if (this.$route.params.type == 'view') {
      this.title = '查看计划任务'
      this.formDisabled = true
      this.showDetail(this.$route.params.data)
    } else if (this.$route.params.type == 'edit') {
      this.title = '修改计划任务'
      this.formDisabled = false
      this.showDetail(this.$route.params.data)
    }
  },
  computed: {
    copylistP() {
      let arr = [], custom = this.copyArr.customTree
      arr.push(...this.copyArr.zeroTree)
      arr.push(...this.copyArr.oneTree)
      arr.push(...this.copyArr.twoTree)
      arr.push(...this.copyArr.threeTree)
      // arr.push(...this.copyArr.fourTree)
      // arr.push(...this.copyArr.fiveTree)
      // arr.push(...this.copyArr.sevenTree)
      for (let a = 0; a < custom.length; a++) {
        for (let b = 0; b < arr.length; b++) {
          if (custom[a].label == arr[b].label) {
            custom.splice(a, 1)
          }
        }
      }
      arr.push(...this.copyArr.customTree)
      return arr
    }
  },
  methods: {
    async selectAll() {
      await organizationService.findAll().then(async res => {
        await res.data.sort((a, b) => {
          if (a.businessOrg < b.businessOrg) {
            return -1
          }
          if (a.businessOrg > b.businessOrg) {
            return 1
          }
          return 0
        })
        this.organization = res.data
        this.organizaAll = res.dataAll
      })

      // sysUserService.findAll().then(res => {
      //   this.sysUser = res.data
      //   this.getSendTree()
      // })
    },
    copysure() {
      if (this.ruleForm.name.length == 0) {
        this.$alert('请填写群组名称')
        return false
      }
      let arr = []
      arr = this.treeList2.map(item => {
        return {userId: item.id, userName: item.name}
      })
      let obj = {
        groupName: this.ruleForm.name,
        msgGroupUsers: arr
      }
      msgGroupsService.create(obj).then(res => {
        if (res) {
          this.$message({
            type: 'success',
            message: '创建成功'
          })
          this.dialogVisible = false
          this.getCustom()
        }
      })

    },
    getSendTree() {
      let tree = []
      for (let item of this.organization) {
        let obj = {
          id: item.id,
          label: item.name,
          level: 1,
          businessOrg: item.businessOrg,
          children: []
        }
        if (item.sub) {
          for (let key of item.sub) {
            let arr = []
            arr = this.sysUser.filter(fil => {
              if (fil.organiza) {
                return fil.organiza.id == key.id
              }
            }).sort((a, b) => {
              if (a.level < b.level) {
                return 1
              } else {
                return -1
              }
              return 0
            })
            arr = arr.map(ma => {
              return {id: ma.id, label: ma.fullname, pId: ma.organiza.id, pBusinessOrg: ma.organiza.businessOrg}
            })
            obj.children.push({
              id: key.id,
              label: key.name,
              businessOrg: key.businessOrg,
              pId: item.id,
              level: 2,
              children: arr
            })
          }
        }
        tree.push(obj)
      }
      this.groupData = tree
    },
    getCustom() {
      msgGroupsService.search().then(res => {
        this.Custom = res.map(item => {
          let arr = []
          if (item.msgGroupUsers) {
            for (let key of item.msgGroupUsers) {
              arr.push({
                id: key.userId,
                label: key.userName
              })
            }
          }
          return {id: item.id, label: item.groupName, children: arr}
        })
      })
    },
    async showDetail(data) {
      for (let key in data) {
        if (key == 'id') {
          this.detailId = data[key]
        } else if (key == 'createTime') {
          this.createTime = data[key]
          // this.task.createTime = moment(data[key]).format('YYYY-MM-DD HH:mm:ss')
        } else if (key == 'url' && data[key]) {
          this.form.url = data[key].split(',')
          this.fileImg = data[key].split(',')
          this.fileList = data[key].split(',').map(item => {
            return {
              name: item.substring(item.lastIndexOf('plans/') + 6, item.length),
              link: item
            }
          })
        } else if (key == 'type' && data[key]) {
          this.form.tplansel = data[key]
        } else if (key == 'datetype' && (data[key] == 0 || data[key] == 1)) {
          if (data[key] == 0) {
            this.form.starttime = moment(data['starttime']).format('YYYY-MM-DD HH:mm:ss')
          } else if (data[key] == 1) {
            this.form.definitiontime[0] = moment(data['starttime']).format('YYYY-MM-DD HH:mm:ss')
            this.form.definitiontime[1] = moment(data['endtime']).format('YYYY-MM-DD HH:mm:ss')
          }
        } else if (key == 'periodEnd' && data[key]) {
          this.form.periodEnd = moment(data['periodEnd']).format('YYYY-MM-DD HH:mm:ss')
        } else if (key == 'typeFirst' && data[key]) {
          let obj1 = this.taskType.find(fin => {
            return fin.id == data[key]
          })
          this.form.type1 = data[key]
          if (obj1 && obj1.subset) {
            this.taskType2 = obj1.subset
            let obj2 = obj1.subset.find(fin => {
              return fin.id == data['typeSecond']
            })
            this.form.type2 = data['typeSecond']
            if (obj2 && obj2.subset && data['typeSecond']) {
              this.taskType3 = obj2.subset
              let obj3 = obj2.subset.find(fin => {
                return fin.id == data['typeThird']
              })
              if (obj3 && data['typeThird']) {
                this.form.type3 = data['typeThird']
              }
            }
          }
        } else if (key == 'planOrgs' && data[key]) {
          this.unit.map(item => {
            for (let ele of data[key]) {
              if (item.orgId == ele.orgId) {
                item.num = ele.number
                item.choose = true
              }
            }
            return item
          })
        } else {
          this.form[key] = data[key]
        }
      }
    },
    async getSendList() {
        let obj = {zero: [], one: [], two: [], three: [], four: [], five: [], seven: []}
        this.organizaAll.forEach(async item => {
          switch (item.businessOrg) {
            case 0:
              if(item.parentId){
                if (item.name.indexOf('处领导') < 0) {
                  obj.three.push({
                    id: item.id,
                    label: item.name,
                    children: []
                  })
                }
              }else{
                obj.zero.push({
                  id: item.id,
                  label: item.name,
                  children: []
                })
              }
              break
            case 1:
              obj.one.push({
                id: item.id,
                label: item.name,
                children: []
              })
              break
            case 2:
              obj.two.push({
                id: item.id,
                label: item.name,
                children: []
              })
              break
            case 3:
              if (item.name.indexOf('处领导') < 0) {
                obj.three.push({
                  id: item.id,
                  label: item.name,
                  children: []
                })
              }
              break
            case 4:
              obj.four.push({
                id: item.id,
                label: item.name,
                children: []
              })
              break
            case 5:
              obj.five.push({
                id: item.id,
                label: item.name,
                children: []
              })
              break
            case 7:
              obj.seven.push({
                id: item.id,
                label: item.name,
                children: []
              })
              break
          }
        })
        for (let key in obj) {
          obj[key] = await obj[key].map(item => {
            let arr = this.sysUser.filter(ele => {
              if (ele.organiza) {
                ele.organiza
                return ele.organiza.id == item.id
              }
            })
            arr.sort((a, b) => {
              if (a.level < b.level) {
                return 1
              } else {
                return -1
              }
              return 0
            })
            item.children = arr.map(element => {
              return {id: element.id, label: element.fullname}
            })
            return item
          })
        }
        this.Zero = obj.zero
        this.One = obj.one
        this.Two = obj.two
        if (obj.three[0].id == 70) {
          let eightSea = obj.three[0]
          obj.three.splice(0, 1)
          obj.three.push(eightSea)
        }
        this.Three = obj.three
    },
    typeChange(event) {
      this.form.type2 = ''
      this.taskType2 = []
      this.form.type3 = ''
      this.taskType3 = []
      let type = this.taskType.find(item => {
        return item.id == event
      })
      if (type.subset) {
        this.taskType2 = type.subset
      }
    },
    typeChange2(event) {
      this.form.type3 = ''
      this.taskType3 = []
      let type = this.taskType2.find(item => {
        return item.id == event
      })
      if (type.subset) {
        this.taskType3 = type.subset
      }
    },
    getCopy() {
    },
    getDistribute(id, org) {
      var param = {}
      param.skey = localStorage.getItem('auth')
      param.style = 'plan'
      if (id) {
        param.cuId = id
      }
      this.$axios.get(this.$config['taskDistribute'], {
        params: param
      }).then((res) => {
        var data = res.data.content
        for (var key of data) {
          this.unit.push({
            d_id: key.d_id,
            name: key.name,
            num: '',
            choose: false
          })
        }
        if (org) {
          for (var y of this.unit) {
            for (var x of org) {
              if (y.d_id == x.org_id) {
                y.choose = true
                y.num = x.number
              }
            }
          }
        }
      })
    },
    beforeupload(file) {
      var tpye = file.name.slice(file.name.lastIndexOf('.') + 1)
      if (tpye == 'jpeg' || tpye == 'jpg' || tpye == 'png') {
        this.uploadobj.mimeType = 'image/jpeg'
      } else if (tpye == 'doc' || tpye == 'docx') {
        this.uploadobj.mimeType = 'application/msword'
      } else if (tpye == 'pdf') {
        this.uploadobj.mimeType = 'application/pdf'
      } else if (tpye == 'txt') {
        this.uploadobj.mimeType = 'text/plain'
      }
      this.uploadobj.filename = file.name
      return true
    },
    editsure() {
      this.$root.eventHub.$emit('dialog', 'false')
    },
    editcancel() {
      this.$root.eventHub.$emit('dialog', 'false')
    },
    handleExceed(files, fileList) {
      this.$message.warning(`当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`)
    },
    nodeChange(ele, name) {
      if (this[`check${name}`]) {
        //全选
        this.$refs[ele].setCheckedNodes(this[name])
      } else {
        //取消选中
        this.$refs[ele].setCheckedKeys([])
      }
    },
    treeChange(ele) {
      this.$refs[ele].getCheckedNodes()
      this.copyArr[ele] = this.$refs[ele].getCheckedNodes().filter(item => {
        return !item.children
      })
    },
    creatsure() {
      if (!this.form.name.trim()) {
        this.$alert('请输入任务名称')
        return false
      }
      if (!this.form.periodEnd.trim()) {
        this.$alert('请输入任务完成期限')
        return false
      }
      //任务计划
      var starttime, endtime
      if (this.form.datetype == '0') {
        var duration
        switch (this.form.tplansel) {
          case 'year':
            duration = 12
            break
          case 'season':
            duration = 3
            break
          case 'month':
            duration = 1
            break
        }
        if (this.form.starttime) {

          starttime = moment(this.form.starttime).toISOString()
          endtime = moment(this.form.starttime).add(duration, 'months').toISOString()
          // endtime.setMonth(endtime.getMonth() + duration)
          // var month = (endtime.getMonth() + 1)
          // var day = endtime.getDate()
          // if (month < 10) {
          //   month = '0' + month
          // }
          // if (day < 10) {
          //   day = '0' + day
          // }
          // endtime = endtime.getFullYear() + '-' + month + '-' + day
        } else {
          this.$alert('请选择计划任务日期时间')
          return false
        }
      } else if (this.form.datetype == '1') {
        if (this.form.definitiontime.length > 1) {
          starttime = moment(this.form.definitiontime[0]).toISOString()
          endtime = moment(this.form.definitiontime[1]).toISOString()
        } else {
          this.$alert('请选择自定义计划任务日期时间')
          return false
        }
      }
      //任务类型
      if (this.form.type1 == 0) {
        this.$alert('请选择任务类型')
        return false
      }

      //任务分配
      var unit = [],
        tasknum = 0
      for (var x of this.unit) {
        if (x.choose == true) {
          unit.push({
            orgId: x.orgId,
            number: x.num * 1
          })
          tasknum += parseInt(x.num)
        }
      }
      //任务数量
      if (this.form.tpbnumber == '0' && this.form.number != tasknum) {
        this.$alert('任务分配数量和任务数量不相等！')
        return
      } else if (this.form.number == 0) {
        this.$alert('请填写任务数量')
        return
      }
      let url = ''
      if (this.form.url) {
        url = this.form.url.join(',')
      }

      let obj = {
        name: this.form.name,
        userName: this.form.userName,
        typeFirst: this.form.type1,
        typeSecond: this.form.type2,
        typeThird: this.form.type3,
        special: this.form.special ? 1 : 0,
        planOrgs: unit,
        number: this.form.number,
        datetype: this.form.datetype,
        type: this.form.tplansel,
        starttime,
        endtime,
        periodEnd: this.form.periodEnd ? moment(this.form.periodEnd).toISOString() : '',
        url,
        userId: this.$profile.id,
        // userName: this.$profile.name,
        userIds: this.copylistP ? this.copylistP.map(item => {
          return item.id
        }) : []
      }
      if (!this.$route.params.type) {
        PlansService.create(obj).then(res => {
          if (res) {
            this.$message({
              type: 'success',
              message: '创建成功'
            })
            this.$emit("close")
          }
        })
      } else if (this.$route.params.type == 'edit') {
        obj.id = this.detailId
        obj.createTime = this.createTime
        PlansService.update(obj).then(res => {
          if (res) {
            this.$message({
              type: 'success',
              message: '修改成功'
            })
            this.$emit("close")
          }
        })
      }
    },
    creatcancel() {
      this.$emit('close')
      for (let key in this.copyArr) {
        this.$refs[key].setCheckedKeys([])
      }
      this.checkZero = false
      this.checkOne = false
      this.checkTwo = false
      this.checkThree = false
      this.checkFour = false
      this.checkFive = false
      this.checkSeven = false
      this.checkCustom = false
    },
    uploadSuccess(res) {
      this.form.url.push(res.data.link)
    },
    uploadRemove: function (res) {
      // this.form.url = ''
    },
    changeType() {
      this.form.tptype2 = ''
      this.taskType2Option = []
      for (var key of this.taskType1Option) {
        if (key.d_id == this.form.tptype1) {
          this.taskType2Option = key.son
        }
      }
    },
    getDetails() {
      this.$axios.get(this.$config['planDetails'], {
        params: {
          skey: localStorage.getItem('auth'),
          d_id: this.id
        }
      }).then((res) => {
        var data = res.data.content.plan[0]

        this.getDistribute(data.cu_id, res.data.content.org)
        this.form.tpname = data.name
        this.form.name = data.fullname

        //to do 创建人
        this.form.tplan = data.datetype
        if (data.datetype == '1') {
          this.form.definitiontime = [data.starttime, data.endtime]
        } else if (data.datetype == '0') {
          this.form.starttime = data.starttime
          var endtime = new Date(data.endtime)
          var days = Math.floor((endtime - new Date(data.starttime)) / (1000 * 60 * 60 * 24))
          if (days < 32) {
            this.form.tplansel = 'month'
          } else if (32 < days < 100) {
            this.form.tplansel = 'season'
          } else {
            this.form.tplansel = 'year'
          }
        }
        this.form.specialitem = data.special == '1' ? true : false
        this.form.typeradio = data.type == '1' ? true : false
        if (this.form.typeradio == true) {
          this.form.typeZ = data.type_firstname
        } else {
          this.changeType(data.type_first)
          this.typex = data.type_second

          this.form.tptype1 = data.type_first
          this.$nextTick(() => {
            this.form.tptype2 = data.type_secondname
          })
        }

        this.form.tpnumipt = data.number
        this.form.numType = data.numberType
        // if (data.period_start) {
        //     var period_start = new Date(data.period_start);
        //     var period_end = new Date(data.period_end);
        //     // this.form.range = [period_start, period_end];

        // }
        this.form.range = data.period_end

        if (data.url != '') {
          this.fileList.push({
            url: data.url
          })
          this.fileImg = data.url.slice(data.url.lastIndexOf('/') + 1)
        }

        //抄送
        if (res.data.content.cshx || res.data.content.csry) {

          var cshx = []
          var per = []
          var ids = []
          for (var x of res.data.content.csry) {
            ids.push('1-' + x.userId)
            per.push(x.fullname)
          }
          for (var x of res.data.content.cshx) {
            ids.push('0-' + x.orgId)
            cshx.push(x.name)
          }
          var copyarr = []
          copyarr = cshx.concat(per)
          this.copylistP = Array.from(new Set(copyarr))
          this.copylista = cshx.concat(per)
          for (var i of ids) {

            for (var j of this.leaderlist) {
              if (j.id == i) {
                this.checkedLeader.push(j)
                break
              }
              for (var x of j.children) {
                if (x.id == i) {
                  this.checkedLeader.push(x)
                  break
                }
              }
            }
            for (var j of this.dows) {
              if (j.id == i) {
                this.checkedDow.push(j)
                break
              }
              for (var x of j.children) {
                if (x.id == i) {
                  this.checkedDow.push(x)
                  break
                }
              }
            }
            for (var j of this.laws) {
              if (j.id == i) {
                this.checkedLaw.push(j)
                break
              }
              for (var x of j.children) {
                if (x.id == i) {
                  this.checkedLaw.push(x)
                  break
                }
              }
            }
            for (var j of this.egs) {
              if (j.id == i) {
                this.checkedEg.push(j)
                break
              }
              for (var x of j.children) {
                if (x.id == i) {
                  this.checkedEg.push(x)
                  break
                }
              }

            }
            for (var j of this.customize) {
              if (j.id == i) {
                this.checkedCustomize.push(j)
                break
              }
              for (var x of j.children) {
                if (x.id == i) {
                  this.checkedCustomize.push(x)
                  break
                }
              }

            }
            for (var j of this.dutys) {
              if (j.id == i) {
                this.checkedDuty.push(j)
                break
              }
              for (var x of j.children) {
                if (x.id == i) {
                  this.checkedDuty.push(x)
                  break
                }
              }
            }

          }
          if (this.$refs.treeLeader) {
            this.$refs.treeLeader.setCheckedNodes(this.checkedLeader)
          }

          if (this.$refs.treeDows) {
            this.$refs.treeDows.setCheckedNodes(this.checkedDow)
          }

          if (this.$refs.treelaws) {
            this.$refs.treelaws.setCheckedNodes(this.checkedLaw)
          }

          if (this.$refs.treeEgs) {
            this.$refs.treeEgs.setCheckedNodes(this.checkedEg)
          }
          if (this.$refs.treeDutys) {
            this.$refs.treeDutys.setCheckedNodes(this.checkedDuty)
          }
          if (this.$refs.treeCustomize) {
            this.$refs.treeCustomize.setCheckedNodes(this.checkedCustomize)
          }

          if (this.leaderlength == this.checkedLeader.length) {
            this.checkLeader = true
          }
          if (this.dowslength == this.checkedDow.length) {
            this.checkDow = true
          }
          if (this.lawslength == this.checkedLaw.length) {
            this.checkLaw = true
          }
          if (this.egslength == this.checkedEg.length) {
            this.checkEg = true
          }
          if (this.dutyslength == this.checkedDuty.length) {
            this.checkDuty = true
          }
          if (this.customizelength == this.checkedCustomize.length) {
            this.checkCustomize = true
          }
        }
      })
    },
    clearData() {
      this.form = {
        code: '',
        tpname: '',
        tplan: 0,
        specialitem: '',
        name: '指挥中心管理员',
        tplansel: 'month',
        starttime: '',
        endtime: '',
        tptype1: '',
        tptype2: '',
        typeZ: '',
        typeradio: false,
        tpbnumber: '0',
        tpnumipt: '',
        range: '',
        definitiontime: '',
        url: '',
        filterContent: {} //清空数据
      }
      for (var key of this.unit) {
        if (key.choose == true) {
          key.choose = false
        }
      }
    },
    //全选
    leaderAll(val) {
      if (val) {
        this.$refs.treeLeader.setCheckedNodes(this.leaderlist)
        this.checkedLeader = this.$refs.treeLeader.getCheckedNodes()
      } else {
        this.$refs.treeLeader.setCheckedNodes([])
        this.checkedLeader = []
      }
      this.makeCopy()
    },
    leaderAllChange(value) {
      let checkedLeader = value.length
      this.checkLeader = checkedLeader === this.leaderlist.length
      this.makeCopy()
    },
    dowAll(val) {
      if (val) {
        this.$refs.treeDows.setCheckedNodes(this.dows)
        this.checkedDow = this.$refs.treeDows.getCheckedNodes()
      } else {
        this.$refs.treeDows.setCheckedNodes([])
        this.checkedDow = []
      }
      this.makeCopy()
    },
    dowAllChange(value) {
      let checkedDow = value.length
      this.checkDow = checkedDow === this.dows.length
      this.makeCopy()
    },
    lawAll(val) {
      if (val) {
        this.$refs.treelaws.setCheckedNodes(this.laws)
        this.checkedLaw = this.$refs.treelaws.getCheckedNodes()
      } else {
        this.$refs.treelaws.setCheckedNodes([])
        this.checkedLaw = []
      }
      this.makeCopy()
    },
    lawAllChange(value) {
      let checkedLaw = value.length
      this.checkLaw = checkedLaw === this.laws.length
      this.makeCopy()
    },
    dutyAll(val) {
      if (val) {
        this.$refs.treeDutys.setCheckedNodes(this.dutys)
        this.checkedDuty = this.$refs.treeDutys.getCheckedNodes()
      } else {
        this.$refs.treeDutys.setCheckedNodes([])
        this.checkedDuty = []
      }
      this.makeCopy()
    },
    dutyAllChange(value) {
      let checkedDuty = value.length
      this.checkDuty = checkedDuty === this.dutys.length
      this.makeCopy()
    },
    customizeAllChange(value) {
      let checkedCustomize = value.length
      this.checkCustomize = checkedCustomize === this.customize.length
      // this.makeCopy()
    },
    egAll(val) {
      if (val) {
        this.$refs.treeEgs.setCheckedNodes(this.egs)
        this.checkedEg = this.$refs.treeEgs.getCheckedNodes()
      } else {
        this.$refs.treeEgs.setCheckedNodes([])
        this.checkedEg = []
      }
      this.makeCopy()
    },
    egAllChange(value) {
      let checkedEg = value.length
      this.checkEg = checkedEg === this.egs.length
      this.makeCopy()
    },
    leaderChange(val, node) {
      this.checkedLeader = node.checkedNodes
      this.makeCopy()

    },
    dowsChange(val, node) {
      this.checkedDow = node.checkedNodes
      this.makeCopy()
    },
    lawsChange(val, node) {
      this.checkedLaw = node.checkedNodes
      this.makeCopy()
    },
    egsChange(val, node) {
      this.checkedEg = node.checkedNodes
      this.makeCopy()
    },
    dutyChange(val, node) {
      this.checkedDuty = node.checkedNodes
      this.makeCopy()
    },
    tptypeChange(id, pid) {

      this.form.tptype1 = pid
      this.$nextTick(() => {
        this.form.tptype2 = id
      })
      this.changeType(pid)
    },
    //:disabled='readread'
    cusClick() {
      this.dialogVisible = true
    },
    //自定义群组
    groupData1() {

    },
    copycancel() {
      this.dialogVisible = false
    },
    clearCopy() {
      this.ruleForm.name = ''
      this.ruleForm.idStr = []
      this.$refs.treeCustomize.setCheckedKeys([])

    },
    handleNodeClick(value) {
      this.dialogVisible1 = true
      this.ruleGroup = value
    }
  }
}
